<template>
  <div class="control-item">
    <div class="control-header">
      <span class="control-name">导航栏</span>
      <span @click="showBeautyBox = true">组件美化</span>
    </div>
    <div class="control-body">
      <div class="control-section">
        <!-- 模板样式 -->
        <div class="control-item">
          <div class="control-title">模板样式</div>
          <div class="control-content">
            <div class="example-list">
              <div
                class="example-item"
                v-for="(item, index) in exampleList"
                @click="setStyleType(item)"
                :class="styleType == item.value ? 'active' : ''"
                :key="index"
              >
                <i class="iconfont" :class="item.icon" />
              </div>
            </div>
          </div>
        </div>
        <!-- 标题 -->
        <div class="control-item title-section" v-if="styleType == 1">
          <div class="control-title flex-between">
            <span>模块标题</span>
            <span class="reset" @click="resetTitle">重置</span>
          </div>
          <div class="control-content">
            <div class="title-name-input">
              <a-input
                placeholder="请输入模板标题"
                v-model="params.params.text"
              />
            </div>
            <div class="hidden-icon" @click="handleHiddenIcon">
              <i
                class="iconfont icon-xianshi"
                v-if="params.params.showText"
              ></i>
              <i class="iconfont icon-yincang" v-else></i>
            </div>
          </div>
        </div>
        <!-- 状态栏颜色 -->
        <div class="control-item capsule-section">
          <div class="control-title flex-between">
            <span>状态栏颜色</span>
            <span class="reset" @click="resetCapsule">重置</span>
          </div>
          <div class="control-content">
            <a-select
              v-model="params.params.capsuleType"
              class="capsule-select"
              @change="capsuleChange"
            >
              <a-select-option value="2"> 白色 </a-select-option>
              <a-select-option value="1"> 黑色 </a-select-option>
            </a-select>
          </div>
        </div>
        <!-- 字体配置 -->
        <fontControl
          :fontData="params.params.css"
          @resetFontCss="resetFontCss"
          :showAlign="styleType == 2 ? false : true"
        ></fontControl>
      </div>
    </div>

    <!-- 组件美化 -->
    <comBeautyBox
      :showBeautyBox="showBeautyBox"
      @handleBack="showBeautyBox = false"
    >
      <div>
        <!-- 字体配置 -->
        <bgControl
          :backgroudData="params.moduleCss"
          sizeText="750*128"
        ></bgControl>
      </div>
    </comBeautyBox>
  </div>
</template>

<script>
import { pageHeader } from "@/components/DiyNew/diy/dataConfig/config.js";
import fontControl from "@/components/DiyNew/diy/baseControl/fontControl/index.vue";
import bgControl from "@/components/DiyNew/diy/baseControl/bgControl/index.vue";
import comBeautyBox from "@/components/DiyNew/diy/comBeautyBox/comBeautyBox.vue";

export default {
  name: "pageHeader",
  components: {
    fontControl,
    bgControl,
    comBeautyBox,
  },
  props: {
    params: {
      type: Object,
      default: {},
    },
  },
  data() {
    return {
      exampleList: [
        {
          icon: 'icon-biaotiwenzi',
          type: "模板1",
          value: "1",
        },
      ],
      showBeautyBox: false,
    };
  },
  watch: {},
  computed: {
    styleType: {
      get() {
        return this.params.params.styleType || "1";
      },
    },
    isIndexPage() {
      let page = this.$diyObser.store.currentPage;
      return page.is_index == 1;
    },
  },
  created() {
    if (this.isIndexPage) {
      this.exampleList.push({
        icon: 'icon-qiehuanmendian',
        type: "模板2",
        value: "2",
      });
    }
  },
  methods: {
    setWithActionItem(e, key) {
      this.$setWithAction(this.params, key, e);
    },
    // 设置样式
    setStyleType(item) {
      this.$set(this.params.params, "styleType", item.value);
      // this.$setWithAction(this.params, "styleType", item.value);
    },
    // 切换胶囊模板
    capsuleChange(e) {
      console.log(e);
      this.$set(this.params.params, "capsuleType", e);
    },
    // 重置字体样式
    resetFontCss() {
      let pageCss = Object.assign({}, pageHeader.params.css);
      this.$set(this.params.params, "css", pageCss);
    },
    // 点击隐藏按钮
    handleHiddenIcon() {
      let flag = this.params.params.showText == 0 ? 1 : 0;
      this.$set(this.params.params, "showText", flag);
    },
    // 点击重置标题按钮
    resetTitle() {
      this.$set(this.params.params, "text", pageHeader.params.text);
      this.$set(this.params.params, "showText", pageHeader.params.showText);
    },
    // 点击重置胶囊按钮
    resetCapsule() {
      this.$set(
        this.params.params,
        "capsuleType",
        pageHeader.params.capsuleType
      );
    },
    resetMdStyle() {
      this.$set(this.params.params, "mdStyle", pageHeader.params.mdStyle);
    },
    mdStyleChange(e) {
      this.$set(this.params.params, "mdStyle", e);
    },
  },
};
</script>

<style lang="scss" scoped>
.control-item {
  width: 100%;
  height: 100%;
  margin: 0 auto;
  .control-header {
    width: 100%;
    height: 48px;
    background: #ffffff;
    border-bottom: 1px solid #f0f2f5;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 24px 14px 24px;
    span {
      font-size: 12px;
      color: #8c8c8c;
    }
    .control-name {
      font-size: 14px;
      font-weight: 600;
      color: #000000;
    }
    span:nth-child(2) {
      cursor: pointer;
    }
  }
  .control-body {
    width: 100%;
    .control-section {
      width: 228px;
      margin: 0 auto;
      text-align: center;
      .control-item {
        width: 100%;
        .control-title {
          padding: 24px 0 14px 0;
          font-size: 12px;
          color: #000000;
          text-align: left;
        }
        .control-content {
          .example-list {
            width: 100%;
            display: flex;
            flex-wrap: wrap;
            .example-item {
              width: 70px;
              height: 70px;
              background: #f6f7f9;
              border-radius: 4px;
              margin-right: 8px;
              display: flex;
              justify-content: center;
              align-items: center;
              cursor: pointer;
              margin-bottom: 8px;
              overflow: hidden;
              .iconfont {
                font-size: 60px;
              }
            }
            .active {
              border: 2px solid #1890fc;
            }
            .example-item:last-child {
              margin-right: 0;
            }
          }
        }
      }
      .title-section,
      .capsule-section {
        .flex-between {
          display: flex;
          justify-content: space-between;
          .reset {
            font-size: 12px;
            color: #9e9e9e;
            cursor: pointer;
          }
        }
        .control-content {
          display: flex;
          align-items: center;
          .title-name-input {
            width: 196px;
            height: 40px;
            border-radius: 4px;
            input {
              height: 100%;
              background-color: #f6f7f9;
              border: 0 none;
            }
            input:hover {
              background-color: #f2f2f2;
            }
          }
          .hidden-icon {
            width: 24px;
            height: 24px;
            background: #f6f7f9;
            border-radius: 4px;
            display: flex;
            justify-content: center;
            align-items: center;
            font-size: 16px;
            margin-left: 8px;
            cursor: pointer;
          }
        }
      }

      .capsule-section {
        .control-content {
          width: 100%;
          height: 40px;
          background: #f6f7f9;
          border-radius: 4px;
          .capsule-select {
            width: 100%;
            height: 100%;
            ::v-deep .ant-select-selection--single {
              height: 100%;
              border: 0 none;
              background: #f6f7f9;
            }
            ::v-deep .ant-select-selection--single:hover {
              background: #f2f2f2;
            }
            ::v-deep .ant-select-selection__rendered {
              line-height: 40px;
            }
          }
        }
      }
    }
  }
}
</style>
